<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>父组件向子组件传递数据——对数据类型进行限定</title>
</head>
<body>
<div id="app">
    <cpn v-bind:message="hobby" v-bind:items="hobbies"></cpn>
    <hr>
    <cpn v-bind:message="movie" v-bind:items="movies"></cpn>
</div>

<template id="cpn">
    <h1>{{ message }}</h1>
    <ul>
        <li v-for="(item, index) in items">{{ item }}</li>
    </ul>
</template>

<script type="module">
    import {createApp, ref, reactive} from "../../../../js/vue.esm-browser.js";
    import {defineComponent} from "../../../../js/vue.esm-browser.js";

    let cpn = defineComponent(
        {
            template: "#cpn",
            props: {
                message: {
                    type: String,
                    default: "内容说明",
                    required: true,
                },
                items: {
                    type: Array,
                    default: [],
                    required: true,
                }
            }
        }
    );

    let app = createApp({
        setup() {
            let hobby = ref("个人爱好")
            let hobbies = reactive(["唱歌", "跳舞", "钢琴"])

            let movie = ref("喜欢的电影")
            let movies = reactive(["叶问", "战狼", "长津湖"])
            return {
                hobby,
                hobbies,
                movie,
                movies,
            }
        },
        components: {
            cpn,
        }
    })

    app.mount("#app")
</script>
</body>
</html>